//
//  AEPointsMallViewCell.m
//  AESOLAR_IOS
//
//  Created by Bin Tang on 2024/10/13.
//  Copyright © 2024 Mr.Wang. All rights reserved.
//

#import "AEPointsMallViewCell.h"
#import "AE_Solar-Swift.h"
#import "AEProductInfoModel.h"

@interface AEPointsMallViewCell ()

@property (nonatomic, strong) AEProductInfoModel *model;

@property (nonatomic, strong) UIImageView *thumalImgView;

/// 商品名称
@property (nonatomic, strong) UILabel *nameLabel;

/// 标签
@property (nonatomic, strong) UILabel *tagLabel;

/// 积分图标
@property (nonatomic, strong) UIImageView *cntImgView;

/// 积分
@property (nonatomic, strong) UILabel *cntLabel;


/// 商品名称
- (void)initWithNameLabel;

/// 标签
- (void)initWithTagLabel;

/// 积分图标
- (void)initWithCntImgView;

/// 积分
- (void)initWithCntLabel;

@end

@implementation AEPointsMallViewCell

- (void)initWithVarCell {
    [super initWithVarCell];
    
}

- (void)initWithSubViewCell {
    [super initWithSubViewCell];
    
    self.contentView.backgroundColor = [UIColor whiteColor];
    
}

- (void)initWithThumalImgView {
    if (!_thumalImgView) {
        CGRect frame = CGRectMake(0, 0, self.contentView.width, self.contentView.width);
        _thumalImgView = [UIImageView createWithImageView:self.contentView frame:frame defaultImage:nil propertiesBlock:^(UIImageView * _Nonnull imageView) {
            imageView.backgroundColor = [UIColor colorWithHexString:@"#F8F8F8"];
            imageView.layer.cornerRadius = 6;
            imageView.layer.masksToBounds = YES;
        }];
    }
    if (self.model) {
        [_thumalImgView sd_setImageWithURL:[NSURL URLWithString:self.model.productImgUrl] placeholderImage:[UIImage imageNamed:@"placeholder_image"]];
    }
}

/// 商品名称
- (void)initWithNameLabel {
    if (!_nameLabel) {
        CGRect frame = CGRectMake(0, self.thumalImgView.bottom + 6, self.thumalImgView.width, 20);
        _nameLabel = [UILabel createWithLabel:self.contentView frame:frame font:[UIFont systemFontOfSize:14 weight:UIFontWeightMedium] propertiesBlock:^(UILabel * _Nonnull label) {
            label.textColor = [UIColor colorWithHexString:@"#303939"];
//            label.text = @"办公茶杯";
        }];
    }
    if (self.model) {
        self.nameLabel.text = objectNull(self.model.productName);
    }
}

/// 标签
- (void)initWithTagLabel {
    if (!_tagLabel) {
        UIFont *font = [UIFont systemFontOfSize:11 weight:UIFontWeightRegular];
        NSString *title = [AEStringExten localizedValueWithKey:@"积分可换"];
        float width = [title widthForFont:font] + 12;
        CGRect frame = CGRectMake(0, self.nameLabel.bottom + 3, width, 18);
        _tagLabel = [UILabel createWithLabel:self.contentView frame:frame font:font propertiesBlock:^(UILabel * _Nonnull label) {
            label.text = title;
            label.textAlignment = NSTextAlignmentCenter;
            label.textColor = [UIColor colorWithHexString:@"#303939"];
            label.backgroundColor = [UIColor colorWithHexString:@"#F4F7F8"];
            label.layer.cornerRadius = 2;
            label.layer.masksToBounds = YES;
        }];
    }
}

/// 积分图标
- (void)initWithCntImgView {
    if (!_cntImgView) {
        UIImage *image = [UIImage imageNamed:@"ic_point_cnt"];
        CGRect frame = CGRectMake(0, self.tagLabel.bottom + 10, image.size.width, image.size.height);
        _cntImgView = [UIImageView createWithImageView:self.contentView frame:frame defaultImage:image propertiesBlock:^(UIImageView * _Nonnull imageView) {
            
        }];
    }
}

/// 积分
- (void)initWithCntLabel {
    if (!_cntLabel) {
        CGRect frame = CGRectMake(self.cntImgView.right + 4, 0, self.thumalImgView.width - self.cntImgView.right - 4, 20);
        _cntLabel = [UILabel createWithLabel:self.contentView frame:frame font:[UIFont systemFontOfSize:16 weight:UIFontWeightBold] propertiesBlock:^(UILabel * _Nonnull label) {
            label.textColor = [UIColor colorWithHexString:@"#303939"];
//            label.text = @"899";
        }];
        _cntLabel.centerY = self.cntImgView.centerY;
    }
    if (self.model) {
        self.cntLabel.text = [NSString stringWithFormat:@"%zd", self.model.productScore];
    }
}


- (void)updateViewCell:(id)cellEntity {
    
    self.model = cellEntity;
    
    [self initWithThumalImgView];
    
    /// 商品名称
    [self initWithNameLabel];

    /// 标签
    [self initWithTagLabel];

    /// 积分图标
    [self initWithCntImgView];

    /// 积分
    [self initWithCntLabel];

}

@end
